package com.pinc.cpbl;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TableRow;

public class main extends Activity {
	
	private TableRow but_rank;
	private TableRow but_game1;
	private TableRow but_game0;
	private TableRow but_game2;
	private TableRow but_setting;
	private TableRow but_about;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_table_view);
        
        but_rank = (TableRow) this.findViewById(R.id.tableRow6);
        but_game1 = (TableRow) this.findViewById(R.id.tableRow2);
        but_game0 = (TableRow) this.findViewById(R.id.tableRow3);
        but_game2 = (TableRow) this.findViewById(R.id.tableRow4);
        but_setting = (TableRow) this.findViewById(R.id.tableRow8);
        but_about = (TableRow) this.findViewById(R.id.tableRow9);
        
        Intent i = new Intent(this, BroadcastService.class);
        startService(i);

        but_rank.setOnClickListener(new View.OnClickListener() {			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(main.this, show_rank.class);
				startActivity(intent);	
			}
		});
        
        but_game1.setOnClickListener(new gameClickListener(1));
        but_game0.setOnClickListener(new gameClickListener(0));
        but_game2.setOnClickListener(new gameClickListener(2));
        
        but_setting.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(main.this, set_settings.class);
				startActivity(intent);	
			}
		});
        
        but_about.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(main.this, show_about.class);
				startActivity(intent);	
			}
		});
    }
    
    private class gameClickListener implements View.OnClickListener
    {
    	private int which_day;
    	
		public gameClickListener(int which_day) {
			this.which_day = which_day;
		}

		@Override
		public void onClick(View v) {
			Bundle bd = new Bundle();
			Intent intent = new Intent(main.this, show_game.class);
			bd.putInt("day", which_day);
			intent.putExtras(bd);
			startActivity(intent);
		}
    }
}